import 'package:flutter/material.dart';

import '../../tool/slide_page_route.dart';
import '../show_image/show_image_page.dart';
import 'assets_image.dart';

/// FileName tap_assets_image
///
/// @Author lax
/// @Date 2024/6/3
///
/// @Description

class TapAssetsImage extends StatelessWidget {
  final double? width;

  final double? height;

  final double? size;

  final double? radius;

  final String? url;

  final String? path;

  final String? name;

  final String? package;

  final Color? bgColor;

  final Color? color;

  final BoxFit? fit;

  final EdgeInsets? margin;

  final EdgeInsets? padding;

  final VoidCallback? onTap;

  const TapAssetsImage({
    super.key,
    this.width,
    this.height,
    this.size,
    this.radius,
    this.url,
    this.path,
    this.name,
    this.package,
    this.bgColor,
    this.color,
    this.fit = BoxFit.contain,
    this.margin,
    this.padding,
    this.onTap,
  });

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      child: AssetsImage(
        width: width,
        height: height,
        size: size,
        radius: radius,
        url: url,
        path: path,
        name: name,
        package: package,
        bgColor: bgColor,
        color: color,
        fit: fit,
        margin: margin,
        padding: padding,
      ),
      onTap: () {
        if (onTap == null) {
          Navigator.push(context, SlidePageRoute(builder: (_) {
            return ShowImagePage(
              bundlePath: AssetsImage.imagePath(path: path, name: name),
              urlString: url,
            );
          }));
        } else {
          onTap?.call();
        }
      },
    );
  }
}
